@@ -17,16 +17,13 @@ import ai.pai.lensman.base.BaseInteractor; |
||
17 | 17 |
import ai.pai.lensman.bean.BriefsBean; |
18 | 18 |
import ai.pai.lensman.bean.MessageBean; |
19 | 19 |
import ai.pai.lensman.bean.SystemMessageBean; |
20 |
-import ai.pai.lensman.main.QueryBoxStatusInteractor; |
|
21 | 20 |
|
22 | 21 |
|
23 |
-public class BriefsPresenter implements BriefsContract.Presenter,BaseInteractor.InteractorListener<BriefsBean>, |
|
24 |
- QueryBoxStatusInteractor.BoxStatusListener { |
|
22 |
+public class BriefsPresenter implements BriefsContract.Presenter,BaseInteractor.InteractorListener<BriefsBean> { |
|
25 | 23 |
|
26 | 24 |
private Context context; |
27 | 25 |
private BriefsContract.View briefsView; |
28 | 26 |
private BriefsInteractor interactor; |
29 |
- private QueryBoxStatusInteractor boxStatusInteractor; |
|
30 | 27 |
|
31 | 28 |
private BriefsBean briefsBean; |
32 | 29 |
private String NULL_STR = ""; |
@@ -39,19 +36,16 @@ public class BriefsPresenter implements BriefsContract.Presenter,BaseInteractor. |
||
39 | 36 |
this.context = context; |
40 | 37 |
this.briefsView = briefsView; |
41 | 38 |
interactor = new BriefsInteractor(this); |
42 |
- boxStatusInteractor = new QueryBoxStatusInteractor(this); |
|
43 | 39 |
} |
44 | 40 |
|
45 | 41 |
@Override |
46 | 42 |
public void start() { |
47 | 43 |
interactor.startJob(); |
48 |
- boxStatusInteractor.startJob(); |
|
49 | 44 |
} |
50 | 45 |
|
51 | 46 |
@Override |
52 | 47 |
public void stop() { |
53 | 48 |
interactor.cancelJob(); |
54 |
- boxStatusInteractor.cancelJob(); |
|
55 | 49 |
if(timer!=null){ |
56 | 50 |
timer.cancel(); |
57 | 51 |
} |
@@ -106,11 +100,6 @@ public class BriefsPresenter implements BriefsContract.Presenter,BaseInteractor. |
||
106 | 100 |
} |
107 | 101 |
|
108 | 102 |
@Override |
109 |
- public void onBoxStatusFetched(String boxNo, String boxStatus, int boxStatusCode) { |
|
110 |
- briefsView.updateBoxInfo(boxNo,boxStatus+"("+boxStatusCode+")"); |
|
111 |
- } |
|
112 |
- |
|
113 |
- @Override |
|
114 | 103 |
public void clickCurrentOrderMsg() { |
115 | 104 |
if(currentMsg == null){ |
116 | 105 |
return; |
@@ -28,7 +28,7 @@ import ai.pai.lensman.service.OrderDealService; |
||
28 | 28 |
import ai.pai.lensman.service.UploadService; |
29 | 29 |
|
30 | 30 |
class MainPresenter implements MainContract.Presenter,SyncTimeInteractor.SyncTimeListener, |
31 |
- UploadService.PhotoUploadListener, QueryBoxStatusInteractor.BoxStatusListener,OrderDealService.OrderServiceListener { |
|
31 |
+ UploadService.PhotoUploadListener, OrderDealService.OrderServiceListener { |
|
32 | 32 |
|
33 | 33 |
private int sessionSeq; |
34 | 34 |
private String lensmanId; |
@@ -38,7 +38,6 @@ class MainPresenter implements MainContract.Presenter,SyncTimeInteractor.SyncTim |
||
38 | 38 |
private MainContract.View view; |
39 | 39 |
|
40 | 40 |
private SyncTimeInteractor syncTimeInteractor; |
41 |
- private QueryBoxStatusInteractor boxStatusInteractor; |
|
42 | 41 |
private ServiceConnection uploadServiceConnection; |
43 | 42 |
private ServiceConnection orderServiceConnection; |
44 | 43 |
|
@@ -64,7 +63,6 @@ class MainPresenter implements MainContract.Presenter,SyncTimeInteractor.SyncTim |
||
64 | 63 |
this.view = view; |
65 | 64 |
this.lensmanId = Preferences.getInstance().getLensManId(); |
66 | 65 |
|
67 |
- boxStatusInteractor = new QueryBoxStatusInteractor(this); |
|
68 | 66 |
syncTimeInteractor = new SyncTimeInteractor(lensmanId,this); |
69 | 67 |
uploadServiceConnection = new ServiceConnection() { |
70 | 68 |
@Override |
@@ -103,7 +101,6 @@ class MainPresenter implements MainContract.Presenter,SyncTimeInteractor.SyncTim |
||
103 | 101 |
if(!isTimeSync){ |
104 | 102 |
syncTimeInteractor.startJob(); |
105 | 103 |
} |
106 |
- boxStatusInteractor.startJob(); |
|
107 | 104 |
registerWifiChangeReceiver(); |
108 | 105 |
App.getAppContext().startService(new Intent(App.getAppContext(), OrderDealService.class)); |
109 | 106 |
App.getAppContext().bindService(new Intent(App.getAppContext(),OrderDealService.class), |
@@ -129,7 +126,6 @@ class MainPresenter implements MainContract.Presenter,SyncTimeInteractor.SyncTim |
||
129 | 126 |
|
130 | 127 |
@Override |
131 | 128 |
public void stop() { |
132 |
- boxStatusInteractor.cancelJob(); |
|
133 | 129 |
App.getAppContext().unbindService(uploadServiceConnection); |
134 | 130 |
App.getAppContext().unbindService(orderServiceConnection); |
135 | 131 |
App.getAppContext().unregisterReceiver(wifiReceiver); |
@@ -208,18 +204,6 @@ class MainPresenter implements MainContract.Presenter,SyncTimeInteractor.SyncTim |
||
208 | 204 |
App.getAppContext().registerReceiver(wifiReceiver,filter); |
209 | 205 |
} |
210 | 206 |
|
211 |
- |
|
212 |
- @Override |
|
213 |
- public void onBoxStatusFetched(String boxNo, String boxStatus, int boxStatusCode) { |
|
214 |
- if(200 == boxStatusCode){ |
|
215 |
- isBoxConnected = true; |
|
216 |
- view.showBoxConnectedView(); |
|
217 |
- }else{ |
|
218 |
- isBoxConnected = false; |
|
219 |
- view.showBoxDisconnectedView(); |
|
220 |
- } |
|
221 |
- } |
|
222 |
- |
|
223 | 207 |
@Override |
224 | 208 |
public void onOrderArrived() { |
225 | 209 |
if(!isBoxConnected){ |
@@ -1,116 +0,0 @@ |
||
1 |
-package ai.pai.lensman.main; |
|
2 |
- |
|
3 |
- |
|
4 |
-import android.os.AsyncTask; |
|
5 |
- |
|
6 |
-import com.android.common.executors.ThreadExecutor; |
|
7 |
- |
|
8 |
-import org.json.JSONObject; |
|
9 |
- |
|
10 |
-import java.util.Random; |
|
11 |
-import java.util.Timer; |
|
12 |
-import java.util.TimerTask; |
|
13 |
- |
|
14 |
-import ai.pai.lensman.BuildConfig; |
|
15 |
-import ai.pai.lensman.base.BaseInteractor; |
|
16 |
-import ai.pai.lensman.utils.BoxUrlContainer; |
|
17 |
-import ai.pai.lensman.utils.HttpPostTask; |
|
18 |
- |
|
19 |
-public class QueryBoxStatusInteractor implements BaseInteractor{ |
|
20 |
- |
|
21 |
- private HttpPostTask queryBoxTask; |
|
22 |
- private BoxStatusListener listener; |
|
23 |
- private Timer queryTimer; |
|
24 |
- private boolean isCancelled; |
|
25 |
- |
|
26 |
- public QueryBoxStatusInteractor(BoxStatusListener listener){ |
|
27 |
- this.listener = listener; |
|
28 |
- } |
|
29 |
- |
|
30 |
- @Override |
|
31 |
- public void startJob() { |
|
32 |
- cancelJob(); |
|
33 |
- queryTimer = new Timer(); |
|
34 |
- queryTimer.schedule(new TimerTask() { |
|
35 |
- @Override |
|
36 |
- public void run() { |
|
37 |
- queryBoxStatus(); |
|
38 |
- } |
|
39 |
- },100,5000); |
|
40 |
- |
|
41 |
- } |
|
42 |
- |
|
43 |
- private void queryBoxStatus(){ |
|
44 |
- queryBoxTask = new HttpPostTask(null){ |
|
45 |
- |
|
46 |
- int boxStatusNum; |
|
47 |
- String boxStatusMsg; |
|
48 |
- String boxNo; |
|
49 |
- @Override |
|
50 |
- protected boolean parseResponse(String response) { |
|
51 |
- try{ |
|
52 |
- JSONObject json = new JSONObject(response); |
|
53 |
- int status = json.getInt("status"); |
|
54 |
- if(status == 200){ |
|
55 |
- JSONObject data = json.getJSONObject("data"); |
|
56 |
- boxNo = data.getString("no."); |
|
57 |
- JSONObject boxStatus = data.getJSONObject("status"); |
|
58 |
- boxStatusMsg = boxStatus.getString("msg"); |
|
59 |
- boxStatusNum = boxStatus.getInt("code"); |
|
60 |
- return true; |
|
61 |
- } |
|
62 |
- }catch (Exception e){ |
|
63 |
- e.printStackTrace(); |
|
64 |
- } |
|
65 |
- return false; |
|
66 |
- } |
|
67 |
- |
|
68 |
- @Override |
|
69 |
- protected void onPostFail() { |
|
70 |
- super.onPostFail(); |
|
71 |
- if(isCancelled){ |
|
72 |
- return; |
|
73 |
- } |
|
74 |
- if(BuildConfig.isTestMode){ |
|
75 |
- if(listener!=null){ |
|
76 |
- listener.onBoxStatusFetched("123","状态消息",100*new Random().nextInt(3)+new Random().nextInt(3)); |
|
77 |
- } |
|
78 |
- return; |
|
79 |
- } |
|
80 |
- } |
|
81 |
- |
|
82 |
- @Override |
|
83 |
- protected void onPostSuccess() { |
|
84 |
- super.onPostSuccess(); |
|
85 |
- if(isCancelled){ |
|
86 |
- return; |
|
87 |
- } |
|
88 |
- if(listener!=null){ |
|
89 |
- listener.onBoxStatusFetched(boxNo,boxStatusMsg,boxStatusNum); |
|
90 |
- } |
|
91 |
- } |
|
92 |
- }; |
|
93 |
- queryBoxTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), BoxUrlContainer.BOX_INFO_URL); |
|
94 |
- } |
|
95 |
- |
|
96 |
- @Override |
|
97 |
- public void cancelJob() { |
|
98 |
- if(queryTimer!=null){ |
|
99 |
- queryTimer.cancel(); |
|
100 |
- queryTimer = null; |
|
101 |
- } |
|
102 |
- if(queryBoxTask==null){ |
|
103 |
- return; |
|
104 |
- } |
|
105 |
- if(queryBoxTask.getStatus()== AsyncTask.Status.RUNNING){ |
|
106 |
- queryBoxTask.cancel(true); |
|
107 |
- } |
|
108 |
- isCancelled = true; |
|
109 |
- queryBoxTask = null; |
|
110 |
- } |
|
111 |
- |
|
112 |
- public interface BoxStatusListener{ |
|
113 |
- |
|
114 |
- void onBoxStatusFetched(String boxNo, String boxStatus, int boxStatusCode); |
|
115 |
- } |
|
116 |
-} |
@@ -14,15 +14,12 @@ import ai.pai.lensman.bean.PhotoBean; |
||
14 | 14 |
import ai.pai.lensman.bean.SessionBean; |
15 | 15 |
import ai.pai.lensman.db.DBService; |
16 | 16 |
import ai.pai.lensman.db.Preferences; |
17 |
-import ai.pai.lensman.main.QueryBoxStatusInteractor; |
|
18 | 17 |
import ai.pai.lensman.service.UploadService; |
19 | 18 |
|
20 | 19 |
|
21 |
-public class SessionPresenter implements SessionContract.Presenter, SessionInteractor.SessionListener, |
|
22 |
- QueryBoxStatusInteractor.BoxStatusListener { |
|
20 |
+public class SessionPresenter implements SessionContract.Presenter, SessionInteractor.SessionListener{ |
|
23 | 21 |
|
24 | 22 |
private SessionInteractor interactor; |
25 |
- private QueryBoxStatusInteractor boxStatusInteractor; |
|
26 | 23 |
private ArrayList<PhotoBean> photoList; |
27 | 24 |
private SessionContract.View sessionView; |
28 | 25 |
private SessionBean sessionBean; |
@@ -42,7 +39,6 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter |
||
42 | 39 |
isWorking = true; |
43 | 40 |
LogHelper.d(TAG,"SessionPresenter start "+sessionBean); |
44 | 41 |
interactor = new SessionInteractor(sessionBean, this); |
45 |
- boxStatusInteractor = new QueryBoxStatusInteractor(this); |
|
46 | 42 |
photoList = DBService.getInstance().getPhotoListBySessionId(sessionBean.sessionId); |
47 | 43 |
if (photoList.size() == 0) { |
48 | 44 |
LogHelper.d(TAG,"SessionPresenter start and found no old photos"); |
@@ -55,7 +51,6 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter |
||
55 | 51 |
} |
56 | 52 |
} |
57 | 53 |
interactor.startSession(); |
58 |
- boxStatusInteractor.startJob(); |
|
59 | 54 |
refreshTimer = new Timer(); |
60 | 55 |
refreshTimer.schedule(new TimerTask() { |
61 | 56 |
@Override |
@@ -68,7 +63,6 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter |
||
68 | 63 |
|
69 | 64 |
@Override |
70 | 65 |
public void stop() { |
71 |
- boxStatusInteractor.cancelJob(); |
|
72 | 66 |
interactor.endSession(); |
73 | 67 |
refreshTimer.cancel(); |
74 | 68 |
Preferences.getInstance().setCurrentSession(""); |
@@ -141,14 +135,4 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter |
||
141 | 135 |
this.groupId = groupId; |
142 | 136 |
} |
143 | 137 |
|
144 |
- @Override |
|
145 |
- public void onBoxStatusFetched(String boxNo, String boxStatus, int boxStatusCode) { |
|
146 |
- LogHelper.d(TAG,"onBoxStatusFetched 盒子当前状态 "+boxStatus+" code = "+boxStatusCode); |
|
147 |
- if(boxStatusCode == 200){ |
|
148 |
- sessionView.showBoxConnectedView(); |
|
149 |
- }else{ |
|
150 |
- sessionView.showBoxDisconnectedView(boxStatusCode,boxStatus); |
|
151 |
- } |
|
152 |
- } |
|
153 |
- |
|
154 | 138 |
} |
@@ -23,6 +23,4 @@ public class BoxUrlContainer { |
||
23 | 23 |
*/ |
24 | 24 |
public static String FETCH_ORIGIN_URL = BASE_URL +"fetch_origin"; |
25 | 25 |
|
26 |
- public static String BOX_INFO_URL = BASE_URL+"box_info"; |
|
27 |
- |
|
28 | 26 |
} |